package cn.kooki.app.duobao.ui.view;

import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import cn.kooki.app.duobao.R;

/**
 * Created by xiong on 2015/11/28.
 */
public class LoadingProgressView extends RelativeLayout {

    private Context context;
    //    private Animation animation;
    private ProgressBar loadingwarpper;
    private View loading;
    private Paint paint;
    private int height;
    private int width;
    private Bitmap onepic;
    private Bitmap warpper;
    private Rect rect;
    private Rect rerect;
    private int bitmapwidth;
    private int rotate = 0;
    private ValueAnimator valueAnimator;
    private Animation animation;
    private FrameLayout red_loading;
    private View whtle_loading;
    private ProgressBar wloadingwarpperwhite;

    private boolean iswhitle = false;

    public LoadingProgressView(Context context) {
        this(context, null);

    }

    public void setIswhitle(boolean iswhitle) {
        this.iswhitle = iswhitle;
    }

    private void init() {
        LayoutInflater.from(context).inflate(R.layout.layout_loading, this, true);
        loadingwarpper = (ProgressBar) findViewById(R.id.w_loading_wrapper);
        red_loading = (FrameLayout) findViewById(R.id.loading_layout_wrapper);
        whtle_loading = findViewById(R.id.w_loading_white);
        wloadingwarpperwhite = (ProgressBar) findViewById(R.id.w_loading_wrapper_white);
        startAniation();
    }


    public void stopAniation() {
        red_loading.setVisibility(GONE);
        whtle_loading.setVisibility(GONE);
    }

    public void startAniation() {

        if (iswhitle) {
            red_loading.setVisibility(GONE);
            whtle_loading.setVisibility(VISIBLE);
        } else {
            red_loading.setVisibility(VISIBLE);
            whtle_loading.setVisibility(GONE);
        }

    }

    public LoadingProgressView(Context context, AttributeSet attrs) {

        this(context, attrs, 0);
    }

    public LoadingProgressView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        init();

    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public LoadingProgressView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();

    }


}
